package com.iplant.basic.controller.bfc;

import com.iplant.base.po.Pagination;
import com.iplant.base.po.RequestMappingAPI;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.TraceLogInfo;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.annotation.trace.TraceAPI;
import com.iplant.base.utils.annotation.trace.TraceModuleAPI;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.log.TraceLoggerTool;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/TraceLogInfo")
@TraceModuleAPI("内部接口日志")
public class TraceLogInfoController extends BasicController<TraceLogInfo> {
    private static Logger logger = LoggerFactory.getLogger(TraceLogInfoController.class);


    public TraceLogInfoController() {
        super(TraceLogInfo.class);
    }

    /**
     * 条件查询
     */
    @TraceAPI("批量查询")
    @GetMapping("/All")
    public Object All(HttpServletRequest request) {
        Object wResult;
        try {
            BMSEmployee wLoginUser = GetSession(request);

            Map<String, Object> wParams = GetParamsMap(request);
            Pagination wPagination = GetPagination(request);

            if (!wParams.containsKey("ProjectName")) {
                String wProjectName = GetRealProjectName(request);
                if (wProjectName.startsWith("/"))
                    wProjectName = wProjectName.substring(1);
                wParams.put("ProjectName", wProjectName);
            }

            ServiceResult<List<TraceLogInfo>> wServiceResult = mPoService.SelectPOList(wLoginUser, wParams, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }

}
